package day02;

import java.util.*;

public class ProxyList<T> implements List<T> {

    private final ArrayList<T> target;

    public ProxyList(ArrayList<T> target){
        this.target = target;
    }

    @Override
    public boolean add(T t) {
        synchronized (target) {
            return target.add(t);
        }
    }

    @Override
    public int size() {
        synchronized (target) {
            return target.size();
        }
    }

    @Override
    public boolean isEmpty() {
        synchronized (target) {
            return target.isEmpty();
        }
    }

    @Override
    public String toString() {
        synchronized (target) {
            return target.toString();
        }
    }

    @Override
    public boolean contains(Object o) {
        synchronized (target) {
            return target.contains(o);
        }
    }

    @Override
    public Iterator<T> iterator() {
        synchronized (target) {
            return target.iterator();
        }
    }

    @Override
    public Object[] toArray() {
        synchronized (target) {
            return target.toArray();
        }
    }

    @Override
    public <T1> T1[] toArray(T1[] a) {
        synchronized (target) {
            return target.toArray(a);
        }
    }

    @Override
    public boolean remove(Object o) {
        synchronized (target) {
            return target.remove(o);
        }
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        synchronized (target) {
            return target.containsAll(c);
        }
    }

    @Override
    public boolean addAll(Collection<? extends T> c) {
        synchronized (target) {
            return target.addAll(c);
        }
    }

    @Override
    public boolean addAll(int index, Collection<? extends T> c) {
        synchronized (target) {
            return target.addAll(index, c);
        }
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        synchronized (target) {
            return target.removeAll(c);
        }
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        synchronized (target) {
            return target.retainAll(c);
        }
    }

    @Override
    public void clear() {
        synchronized (target) {
            target.clear();
        }
    }

    @Override
    public T get(int index) {
        synchronized (target) {
            return target.get(index);
        }
    }

    @Override
    public T set(int index, T element) {
        synchronized (target) {
            return target.set(index, element);
        }
    }

    @Override
    public void add(int index, T element) {
        synchronized (target) {
            target.add(index, element);
        }
    }

    @Override
    public T remove(int index) {
        synchronized (target) {
            return target.remove(index);
        }
    }

    @Override
    public int indexOf(Object o) {
        synchronized (target) {
            return target.indexOf(o);
        }
    }

    @Override
    public int lastIndexOf(Object o) {
        synchronized (target) {
            return target.lastIndexOf(o);
        }
    }

    @Override
    public ListIterator<T> listIterator() {
        synchronized (target) {
            return target.listIterator();
        }
    }

    @Override
    public ListIterator<T> listIterator(int index) {
        synchronized (target) {
            return target.listIterator(index);
        }
    }

    @Override
    public List<T> subList(int fromIndex, int toIndex) {
        synchronized (target) {
            return target.subList(fromIndex, toIndex);
        }
    }
}
